<template>
  <div class="main_box">
    <el-row class="header-row">
      <el-col>
        <div class="opration_wrap">
          <el-tooltip content="刷新" placement="top">
            <el-button circle icon="el-icon-refresh-right" @click="reload" size="mini"></el-button>
          </el-tooltip>
          <div>
            <el-button type="primary" plain icon="fa fa-plus" @click="handleClickAdd()" size="mini"> 新增</el-button>
          </div>
        </div>
      </el-col>
    </el-row>
    <el-row ref="tableRow">
      <!-- 列表 -->
      <el-table :data="barcodeList" :fit="true" highlight-current-row>
        <el-table-column type="selection" width="50"></el-table-column>

        <el-table-column prop="institutionName" label="医检名称" width="160"></el-table-column>
        <el-table-column prop="codePre" label="条码号前缀" width="200"></el-table-column>
        <el-table-column prop="lengthMin" label="最小长度" width="150"></el-table-column>
        <el-table-column prop="lengthMax" label="最大长度" width="150"></el-table-column>
        <el-table-column label="状态" width="100" align="center" prop="state">
          <template slot-scope="scope">
            <span>
              <el-tag size="mini" effect="dark" :type="formatStates(scope.row.state)">
                {{ formatStates(scope.row.state) }}
              </el-tag>
            </span>
          </template>
        </el-table-column>
        <el-table-column prop="createDate" label="创建时间" width="250"></el-table-column>
        <el-table-column prop="remark" label="备注"></el-table-column>
        <el-table-column label="操作" width="200" align="left">
          <template slot-scope="scope">
            <el-button @click="handleClickEditor(scope.row)" size="mini">编辑</el-button>
            <el-button @click="handleClickDelete(scope.row)" size="mini">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页工具条 -->
      <el-pagination
        background
        :current-page="page.pageNo"
        :page-sizes="[20, 50, 100]"
        :page-size="page.pageSize"
        layout="total, sizes, jumper, next, pager, prev"
        :total="page.pageTotal"
      ></el-pagination>
    </el-row>
  </div>
</template>

<script>
import * as message from '@/constants/message';
import BarodeApi from '@/api/institution/barode';

export default {
  name: 'BarcodeManagement',
  inject: ['reload'], //注入局部刷新
  data() {
    return {
      barcodeList: [],
      page: {
        pageNo: 1,
        pageTotal: 0,
        pageSize: 20,
      },

    };
  },
  mounted() {
    this.init();
  },
  activated() {
    this.init();
  },
  methods: {
    init() {
      this.listBarode();
      this.getTableHeight();
    },
    listBarode() {
      console.log('aaaaaaaaaaaaaaaaaa111111111');
      let _this = this;
      let cond = {
        pageNo: _this.page.pageNo,
        pageSize: _this.page.pageSize,
      };
      BarodeApi.getBarode(cond).then((res) => {
        this.barcodeList = res.data.list;
        _this.page.pageTotal = res.data.total;
      });
    },

    //获取当前条形码的状态
    formatStates(cellValue) {
      if (cellValue == -1) {
        return '删除';
      } else if (cellValue == 0) {
        return '禁用';
      } else if (cellValue == 1) {
        return '启用';
      }
    },
    //编辑操作
    handleClickEditor(row) {
      console.log('handleClickEditor', row);
      let _this = this;
      _this.$router.push({
        name: 'barodeAdd',
        params: { rowData: row },
      });
    },
    //删除操作
    handleClickDelete(val) {
      let _this = this;
      _this.$confirm(message.MSG_CONFIRM_DELETE, message.TITLE_PROMPT, {}).then(() => {
        let code = {
          codePre: val.codePre,
          lengthMin: val.lengthMin,
          lengthMax: val.lengthMax,
          institutionId: val.institutionId,
          remark: val.remark,
          state: 2,
          id: val.insCodeRuleId,
        };
        BarodeApi.delBarode(code).then((res) => {
          _this.listBarode();
          this.$Utils.notifySuccess();
        });
      });
    },
    //新增操作
    handleClickAdd() {
      let _this = this;
      _this.$router.push('/institu/barodeAdd');
    },
  },
};
</script>

<style lang="scss" src="@/assets/css/views/content.scss" scope></style>
